{include file="public/nheader"}
<div class="layui-fluid layui-bg-white">
    <form action="{:url()}" class="layui-form layui-form-fixed">
        <div class="layui-form layui-form-fixed">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    选择组合
                </label>
                <div class="layui-input-block">
                    <select name="taocanid" lay-filter="taocanid" required="" lay-verify="required">
                        <option value="">请选择组合</option>
                        {foreach $taocans as $v}
                        <option value="{$v.id}" {if !empty($taocanid) && $taocanid==$v.id}selected{/if}>
                            {$v.titles}{if $v.isshow == 2}(已隐藏){/if}
                        </option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    产品列表
                </label>
                <div class="layui-input-block">
                    <table class="layui-table">
                        <thead>
                            <tr>
                                <th width="50">产品ID</th>
                                <th width="150">名称</th>
                                <th width="100">规格</th>
                                <th width="100">单位</th>
                                <th width="50">单价</th>
                                <th style="min-width: 100px;">数量</th>
                            </tr>
                        </thead>
                        <tbody>
                            {if !empty($product)}
                            {foreach $product as $k => $tc}
                            <tr>
                                <input name="goods[{$k}][id]" type="hidden" value="{$tc.id|default='0'}" />
                                <td>{$tc.id|default=''}</td>
                                <td>{$tc.title|default=''}</td>
                                <td>{$tc.guige|default=''}</td>
                                <td>{$tc.unit|default=''}</td>
                                <td>{$tc.price|default=''}元</td>
                                <td><input class="layui-input" required="" placeholder="请填写组合产品数量" lay-verify="required"
                                        name="goods[{$k}][numbers]" type="number" value="" /></td>
                                </td>
                            </tr>
                            {/foreach}
                            {/if}
                        </tbody>
                    </table>

                </div>
                <div class="layui-input-block" style="color: red;">
                    注意:隐藏下架和删除的产品在小程序用户端不会显示，组合内已添加的产品会更新数量,添加完后可在组合清单内调整核对</div>
            </div>
        </div>
        <div class="layui-footer layui-form-item layui-center ">
            <button data-reload="top" class="layui-btn" lay-filter="submitIframes" type="button" lay-submit>添加</button>
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closeDialog">取消</button>
        </div>
    </form>
</div>
{include file="public/nfooter"}
<script>
    function taocan(id) {
        layui.$.post("{:url('agent/taocanlog_del')}", { id: id }, function (res) {
            if (res.code == 200) {
                layer.msg(res.msg);
                location.reload();
            } else {
                layer.error(res.msg);
            }
        }, 'json');
        return false;
    }
    layui.use(['form', 'layer', 'upload', 'admin'], function () {
        $ = layui.jquery;
        var admin = layui.admin;
        var form = layui.form
            , upload = layui.upload
            , element = layui.element
            , layer = layui.layer;
        
        // 监听权限提交
        form.on("submit(delPage)", function (post) {
            layui.$.post("{:url('agent/taocanlog_del')}", post.field, function (res) {
                if (res.code == 200) {
                    layer.msg(res.msg);
                    // 关闭当前窗口
                    form.render();
                    location.reload();
                } else {
                    layer.error(res.msg);
                }
            }, 'json');
            return false;
        })
        // 监听权限提交
        form.on("submit(submitIframes)", function (post) {
            var taocanid = '{$taocanid}';
            layui.$.post("{:url('agent/taocan_list')}", post.field, function (res) {
                if (res.code == 200) {
                    layer.msg(res.msg);
                    setTimeout(function () {
                        if (taocanid > 0) {
                            parent.location.reload();
                        } else {
                            parent.location.reload();
                        }
                    }, 600); // 延迟时间为 1000 毫秒（1秒）
                    layer.close();
                } else {
                    layer.error(res.msg);
                }
            }, 'json');

            return false;
        })
    });
</script>